/**
 * Copyright &copy; 2012-2014 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.cms.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.cms.entity.ExVideos;
import com.thinkgem.jeesite.modules.cms.service.ExVideosService;

/**
 * 视频Controller
 * @author 夏国强
 * @version 2016-05-30
 */
@Controller
@RequestMapping(value = "${adminPath}/cms/exVideos")
public class ExVideosController extends BaseController {

	@Autowired
	private ExVideosService exVideosService;
	
	@ModelAttribute
	public ExVideos get(@RequestParam(required=false) String id) {
		ExVideos entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = exVideosService.get(id);
		}
		if (entity == null){
			entity = new ExVideos();
		}
		return entity;
	}
	
	@RequiresPermissions("cms:exVideos:view")
	@RequestMapping(value = {"list", ""})
	public String list(ExVideos exVideos, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ExVideos> page = exVideosService.findPage(new Page<ExVideos>(request, response), exVideos); 
		model.addAttribute("page", page);
		return "modules/cms/exVideosList";
	}

	@RequiresPermissions("cms:exVideos:view")
	@RequestMapping(value = "form")
	public String form(ExVideos exVideos, Model model) {
		model.addAttribute("exVideos", exVideos);
		return "modules/cms/exVideosForm";
	}

	@RequiresPermissions("cms:exVideos:edit")
	@RequestMapping(value = "save")
	public String save(ExVideos exVideos, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, exVideos)){
			return form(exVideos, model);
		}
		exVideosService.save(exVideos);
		addMessage(redirectAttributes, "保存视频成功");
		return "redirect:"+Global.getAdminPath()+"/cms/exVideos/?repage";
	}
	
	@RequiresPermissions("cms:exVideos:edit")
	@RequestMapping(value = "delete")
	public String delete(ExVideos exVideos, RedirectAttributes redirectAttributes) {
		exVideosService.delete(exVideos);
		addMessage(redirectAttributes, "删除视频成功");
		return "redirect:"+Global.getAdminPath()+"/cms/exVideos/?repage";
	}

}